package org.wj.config.temperature;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;

import java.io.IOException;
import java.util.Iterator;

public class SecondarySortReducer extends MapReduceBase implements Reducer<DateTemperaturePair, LongWritable, Text, Text> {

    @Override
    public void reduce(DateTemperaturePair key, Iterator<LongWritable> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        while (values.hasNext()) {
            stringBuilder.append(values.next());
            stringBuilder.append(",");
        }
        output.collect(key.getYearMonth(), new Text(stringBuilder.toString()));
    }
}
